package com.example.java.designpattern;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author zengty
 * @apiNote 组合模式
 * @date 2024/8/29
 * @project study
 */
public class CompositeDivisor implements Divisor {

    private final Collection<Divisor> divisors;

    public CompositeDivisor() {
        divisors = new ArrayList<>();
    }

    public CompositeDivisor(Collection<Divisor> divisors) {
        this.divisors = divisors;
    }

    public void addDivisor(Divisor divisor) {
        divisors.add(divisor);
    }

    @Override
    public void divide(String s) {
        for (Divisor divisor : divisors) {
            divisor.divide(s);
        }
    }
}
